package com.foxzzz.dynamic.programming;

public class Solution53 {
    public int maxSubArray(int[] nums) {
        if(nums.length==0)
            return 0;
        int sum=0;
        int max=Integer.MIN_VALUE;
        for (int i = 0; i < nums.length; i++) {
           sum=sum>0?sum+nums[i]:nums[i];
           max=max<sum?sum:max;
        }
        return max;
    }

    public static void main(String[] args) {
        System.out.println(new Solution53().maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4}));
    }
}
